﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using common;
using System.Windows.Forms;
using Dapper;
using System.Data.SqlClient;
using DBEntity;
using DBClass;

namespace HTF_HMI
{
    public partial class AUDIT_LINE : Form
    {
        AutoSizeFormClass asc = new AutoSizeFormClass();

        public AUDIT_LINE()
        {
            InitializeComponent();             
        }

        private void AUDIT_LINE_Load(object sender, EventArgs e)
        {
            asc.controlAutoSize(this);
            DataRow dr;
            DataTable CrewData = new DataTable();
            CrewData.Columns.Add("VALUE", System.Type.GetType("System.String"));
            CrewData.Columns.Add("COMMENT", System.Type.GetType("System.String"));
            dr = CrewData.NewRow();
            dr["VALUE"] = "1";
            dr["COMMENT"] = "甲";
            CrewData.Rows.Add(dr);
            dr = CrewData.NewRow();
            dr["VALUE"] = "2";
            dr["COMMENT"] = "乙";
            CrewData.Rows.Add(dr);
            dr = CrewData.NewRow();
            dr["VALUE"] = "3";
            dr["COMMENT"] = "丙";
            CrewData.Rows.Add(dr);
            //repositoryItemLookUpEdit1.DataSource = CrewData;
            //repositoryItemLookUpEdit1.DisplayMember = "COMMENT";
            //repositoryItemLookUpEdit1.ValueMember = "VALUE";
            btn_query_Click(null,null);
        }

        public void btn_query_Click(object sender, EventArgs e)
        {   
            bindingSource1.DataSource = DBHelper.GetPlan();
        }

        private void btn_new_Click(object sender, EventArgs e)
        {
            //Act_Shutdown_Edit mpSheet = new Act_Shutdown_Edit(this,"");
            //mpSheet.ShowDialog();
        }

        private void btn_edit_Click(object sender, EventArgs e)
        {
            int[] rows = this.gridView1.GetSelectedRows();
            if (rows.Count() == 0)
            {
                MessageBox.Show("请选择要修改的停机报告！");
                return;
            }
            if (rows.Count() == 1)
            {
                string strId = this.gridView1.GetRowCellValue(rows[0], gridView1.Columns["ID"]).ToString();
                //Act_Shutdown_Edit mpSheet = new Act_Shutdown_Edit(this,strId);
                //mpSheet.ShowDialog();
            }

            if (rows.Count() > 1)
            {
                MessageBox.Show("请选择一条要修改的停机报告！");
                return;
            }
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {          
            int[] rows = this.gridView1.GetSelectedRows();
            if (rows.Count() == 0)
            {
                MessageBox.Show("请选择要删除的停机报告！");
                return;
            }
            if (rows.Count() > 0)
            {                
                List<int> ids = new List<int>();
                foreach (int row in rows)
                {
                    int strId = Int32.Parse( this.gridView1.GetRowCellValue(row, gridView1.Columns["ID"]).ToString());                  
                    
                    ids.Add(strId);
                }                
                //bool result = DBHelper.DeleteShutdown(ids);
                //if (result)
                //{
                //    MessageBox.Show("删除成功！");
                //    btn_query_Click(null,null);
                //}
                //else
                //{
                //    MessageBox.Show("删除失败！");
                //}
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

        }
    }
}
